package com.z6school.manage.controller;

import com.z6school.manage.common.pojo.DeptMajorClass;
import com.z6school.manage.common.pojo.JsonResult;
import com.z6school.manage.common.pojo.Nodes;
import com.z6school.manage.po.School;
import com.z6school.manage.service.DMSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dept/")
public class DMSController {
    @Autowired
    private DMSService dmsService;

    @RequestMapping("doFindObjects")
    public JsonResult doFindObjects(){
        List<DeptMajorClass> all = dmsService.findAll();
        return new JsonResult(all);
    }
    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        if (id>1000) dmsService.deleteByClassId(id);
        if (id>100&&id<1000) dmsService.deleteByMajorId(id);
        if (id>1&&id<100) dmsService.deleteByDeptId(id);
        return new JsonResult("delete ok");
    }

    @RequestMapping("doFindZTreeNodes")
    public JsonResult doFindZTreeNodes(){
        List<Nodes> zTreeNodes = dmsService.findZTreeNodes();
        return new JsonResult(zTreeNodes);
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(DeptMajorClass deptMajorClass){
        dmsService.saveObject(deptMajorClass);
        return new JsonResult("添加成功");
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(DeptMajorClass deptMajorClass){
        System.out.println("controller+"+deptMajorClass.getId());
        dmsService.updateObject(deptMajorClass);
        return new JsonResult("修改成功");
    }
}
